package ink.yuanchu.picachoframework.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import ink.yuanchu.picachoframework.dao.UserMapper;
import ink.yuanchu.picachoframework.entity.User;
import ink.yuanchu.picachoframework.service.UserService;
import ink.yuanchu.picachoframework.service.bo.UserBO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @author ziyuan
 * @Date: 2021/03/20/14:04
 * @Description:
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> selectAll() {
        return userMapper.selectAll();
    }

    @Override
    public User findUserByUsername(String name) {
        return userMapper.findUserByUsername(name);
    }

    @Override
    public List<User> findAll() {
        return userMapper.selectList(null);
    }

    @Override
    public int addUser(User user) {
        int insert = userMapper.insert(user);
        return insert;
    }

    @Override
    public Integer findByName(String name) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("username",name);
        Integer integer = userMapper.selectCount(wrapper);
        return integer;
    }

    @Override
    public User findByNameToUser(String name) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("username",name);
        User user = userMapper.selectOne(wrapper);
        return user;
    }

    @Override
    public Integer updateByUserId(User user) {
        return userMapper.updateById(user);
    }


    @Override
    public Integer deleteById(String id) {
        return userMapper.deleteById(id);
    }
}
